let DynamicsData = require("./DynamicsData");
cc.Class({
    extends: cc.Component,

    properties: {
        curScoreLabel: cc.Label,
        maxScoreLabel: cc.Label,
    },



    onLoad() {
        this.curScore = 0;
        this.maxScore = cc.sys.localStorage.getItem("plane_MaxScore");
        if (this.maxScore == null) {
            this.maxScore = 0;
        }
        this.curScoreLabel.string = `当前分数：${this.curScore}`;
        this.maxScoreLabel.string = `最高分数：${this.maxScore}`;
        //先将分数存储到DynamicsData对象中，防止玩家在未击中敌机游戏就结束了，使得分数未存储到DynamicsData中
        //游戏结束界面无法获取当前的分数数据
        DynamicsData.setData("curScore", this.curScore);
        DynamicsData.setData("maxScore", this.maxScore);
    },

    start() {

    },
    //增加分数
    addScore(score) {
        //分数增加的逻辑
        this.curScore += score;
        if (this.maxScore < this.curScore) {
            this.maxScore = this.curScore;
            cc.sys.localStorage.setItem("plane_MaxScore", this.maxScore);
        }
        this.curScoreLabel.string = `当前分数：${this.curScore}`;
        this.maxScoreLabel.string = `最高分数：${this.maxScore}`;
        //将最高分和当前分数都存入到cc中，方便在别项目中的其他脚本可以获取到
        // cc.gameData.curScore = this.curScore;
        // cc.gameData.maxScore = this.maxScore;

        //将最高分和当前分数存入到DynamicsData对象中
        DynamicsData.setData("curScore", this.curScore);
        DynamicsData.setData("maxScore", this.maxScore);

    },
    reduceScore(score) {
        //分数增加的逻辑
        this.curScore -= score;
        if (this.curScore < 0) {
            this.curScore = 0;
        }
        this.curScoreLabel.string = `最高分数：${this.curScore}`;

        //将最高分和当前分数存入到DynamicsData对象中
        DynamicsData.setData("curScore", this.curScore);
    }

    // update (dt) {},
});
